clear
set more off

local titlescore "Occupational"


**** Correlations

use $tempdir/panel_trends_30yr_income.dta, clear
keep if race==1 & spouserace == 1

foreach var in score{

gen corr_reg_`var' = .
gen corr_nat_`var' = .

foreach y in $yearlist {
	foreach r in 1 2 3{
		corr logocc`var'_father logocc`var'_father_spouse if year2==`y' & sex==1 & spouseregion_birth_coarse == `r'
		replace corr_reg_`var' = r(rho) if year2==`y' & spouseregion_birth_coarse == `r'
	}	
	
		corr logocc`var'_father logocc`var'_father_spouse if year2==`y' & sex==1
		replace corr_nat_`var' = r(rho) if year2==`y'
}
}

collapse (mean) corr*, by(year2 spouseregion_birth_coarse)

gen birth_cohort = year2 - 37.5

foreach var in score{


graph twoway scatter  corr_nat_`var' birth_cohort if spouseregion_birth_coarse == 1 & birth_cohort < 1910, sort(year2) connect(direct) lcolor(black) lwidth(thick) mcolor(black) msymbol(circle) msize(large)  || /*
	*/ scatter corr_reg_`var' birth_cohort if spouseregion_birth_coarse == 1 & birth_cohort < 1910, sort(year2) connect(direct) lcolor(gs6) lwidth(medthin) lpattern(dash) mlcolor(gs6) mfcolor(none) msymbol(square) msize(medium) || /*
	*/ scatter corr_reg_`var' birth_cohort if spouseregion_birth_coarse == 2 & birth_cohort < 1910, sort(year2) connect(direct) lcolor(gs6) lwidth(medthin) lpattern(shortdash) mlcolor(gs6) mfcolor(none) msymbol(diamond) msize(medium) || /*
	*/ scatter corr_reg_`var' birth_cohort if spouseregion_birth_coarse == 3 & birth_cohort < 1910, sort(year2) connect(direct) lcolor(gs6) lwidth(medthin) lpattern(dot) mlcolor(gs6) mfcolor(none) msymbol(triangle) msize(medium) /*
	*/ ytitle("Correlation coefficient") xtitle("15 year birth cohort") graphregion(fcolor(white) lcolor(white))  /*
	*/ legend(cols(3) rows(2) holes(1 3) label(1 "National") label(2 "Northeast") label(3 "Midwest") label(4 "South")) 
	
graph export "$outputdir/correlations.pdf", replace

}








